<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <meta http-equiv="X-UA-Compatible" content="ie=edge" />
        <title>07.get方式提交数据注意事项</title>
        <script>
        		
            window.onload = function () {
                var oBtn = document.getElementById("btn1");
                oBtn.addEventListener('click', function () {
                    var oxhr = null;
                    if (window.XMLHttpRequest) {
                        oxhr = new XMLHttpRequest();
                    } else {
                        oxhr = new ActiveXObject("Microsoft.XMLHTTP");
                    }

					/**
					 * get数据是放在url?userName=allen&password=123456
					 * 注意有如下问题：
					 * 1.IE下缓存问题 ---> 解决办法：加时间戳
					 * 2.中文乱码问题 ---> 解决办法：encodeURI
					 */
                    // oxhr.open('GET', './php/1.get.php?userName=allen&password=123456&' + new Date().getTime(), true);
                    oxhr.open('GET', './php/1.get.php?userName=' + encodeURI('小小游') + '&password=123456&' + new Date().getTime(), true);

                    oxhr.send(null);

                    oxhr.onreadystatechange = function () {
                        if (oxhr.readyState == 4) {
                            if ((oxhr.status >= 200 && oxhr.status < 300) || oxhr.status == 304) {
                                alert(oxhr.responseText);
                            } else {
                            		alert('通信失败：' + oxhr.status);
                            }
                        }
                    };
                }, false);
            };
        </script>
    </head>
    <body>
        <input type="button" value="获取GET数据" id="btn1" />
    </body>
</html>
